#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main() {
	long int N = 0;
	cout<<"求平均数 方差 和 中位数"<<endl<<"请输入数据个数"<<endl;
	cin>>N;
	long double data1[N];
	long double data2 = 0 , data3 = 0;
	long double median = 0 , average = 0 , variance = 0;
	cout<<"输入数据（空格，逗号，回车均可作为分割）"<<endl;
	for (int i = 0;i < N;++i) { 
		cin>>data1[i];				//输入到数组 
		data2 += data1[i];			//求总和 
	}
	for(int i = 0;i < N;i++){      //按大小排序 
		for(int j = 0;j < N-i-1;j++){  
            if(data1[j] > data1[j+1]){  
                int t = data1[j];  
                data1[j] = data1[j+1];  
                data1[j+1] = t;  
            }  
        }  
    } 
    if ((N+1) / 2.0 == (int)((N+1) / 2.0))		//判断是否为偶数，采取不同的求中位数方法 
    {
    	int temp = 0;
    	temp = ((N+1) / 2.0) - 1;
    	median = data1[temp];
    } else {
    	int temp = 0;
    	temp = N / 2;
    	median = (data1[temp-1] + data1[temp]) / 2.0;
    } 
    average = ((double)data2 / N);	//求平均数
    for (int i = 0;i < N;++i) { 	//计算方差准备 
    	long double tmp = 0;
		tmp = average - data1[i];
		tmp = tmp * tmp;
		data3+=tmp;
	}
	variance = (data3 / N);		//计算方差 
	cout<<"平均数："<<average<<endl;
	cout<<"中位数："<<median<<endl;
	cout<<"方差  ："<<variance<<endl; 
	cout<<"方差分数："<<data3<<"/"<<N<<endl;
	system("pause");
	return 0;
}
